<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<div>
  <div class="row interpreter">
    <div class="col-md-12" ng-show="showAddNewSetting">
      <hr />
      <div class="interpreterSettingAdd">
        <h4>Create new interpreter</h4>

        <div class="form-group" style="width:200px">
          <b>Name</b>
          <input id="newInterpreterSettingName" input pu-elastic-input
                 pu-elastic-input-minwidth="180px" ng-model="newInterpreterSetting.name" />
        </div>

        <b>Interpreter group</b>
        <div class="form-group"
             style="width:180px">
          <select class="form-control input-sm" ng-model="newInterpreterSetting.group"
                  ng-change="newInterpreterGroupChange()">
            <option ng-repeat="availableInterpreter in availableInterpreters | unique: 'group'| orderBy: 'group'" value="{{availableInterpreter.group}}">
              {{availableInterpreter.group}}
            </option>
          </select>
        </div>

        <b>Option</b>
        <div>
          <span class="btn-group">
            <button type="button" class="btn btn-default btn-xs dropdown-toggle"
                    data-toggle="dropdown">
              {{getSessionOption(setting.id)}} <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu">
              <li>
                <a style="cursor:pointer"
                   tooltip="Single interpreter instance are shared across notes"
                   ng-click="setSessionOption(setting.id, 'shared')">
                  shared
                </a>
              </li>
              <li>
                <a style="cursor:pointer"
                   tooltip="Separate Interpreter instance for each note"
                   ng-click="setSessionOption(setting.id, 'scoped')">
                  scoped
                </a>
              </li>
              <li>
                <a style="cursor:pointer"
                   tooltip="Separate Interpreter process for each note"
                   ng-click="setSessionOption(setting.id, 'isolated')">
                  isolated
                </a>
              </li>
            </ul>
          </span>
          <span>Interpreter for note</span>
        </div>
        <br />
        
        <div class="col-md-12" style="padding-left:0px">
          <div class="checkbox">
            <span class="input-group">
              <label><input type="checkbox" style="width:0%;height:0%" ng-model="newInterpreterSetting.option.isExistingProcess"> </input> Connect to existing process </label>
            </span>
          </div>
        </div>
        <div ng-show="newInterpreterSetting.option.isExistingProcess" class="form-group" style="width:200px">
          <b>Host</b>
            <input id="newInterpreterSettingHost" input pu-elastic-input
              pu-elastic-input-minwidth="180px" ng-model="newInterpreterSetting.option.host" />
        </div>
        <div ng-show="newInterpreterSetting.option.isExistingProcess" class="form-group" style="width:200px">
          <b>Port</b>
           <input id="newInterpreterSettingPort" input pu-elastic-input
            pu-elastic-input-minwidth="180px" ng-model="newInterpreterSetting.option.port" />
        </div>

        <b>Properties</b>
        <table class="table table-striped properties">
          <tr>
            <th>name</th>
            <th>value</th>
            <th>description</th>
            <th>action</th>
          </tr>
          <tr ng-repeat="(key, value) in newInterpreterSetting.properties">
            <td>{{key}}</td>
            <td><textarea msd-elastic ng-model="value.value"></textarea></td>
            <td>{{value.description}}</td>
            <td>
              <button class="btn btn-default btn-sm fa fa-remove" ng-click="removeInterpreterProperty(key)">
              </button>
            </td>
          </tr>

          <tr>
            <td>
              <input pu-elastic-input pu-elastic-input-minwidth="180px"
                     ng-model="newInterpreterSetting.propertyKey" />
            </td>
            <td><textarea msd-elastic ng-model="newInterpreterSetting.propertyValue"></textarea></td>
            <td></td>
            <td>
              <button class="btn btn-default btn-sm fa fa-plus" ng-click="addNewInterpreterProperty()">
              </button>
            </td>
          </tr>
        </table>

        <b>Dependencies</b>
        <table class="table table-striped properties">
          <tr>
            <th>artifact</th>
            <th>exclude</th>
            <th>action</th>
          </tr>

          <tr ng-repeat="dep in newInterpreterSetting.dependencies">
            <td>
              <input ng-model="dep.groupArtifactVersion" style="width:100%" />
            </td>
            <td>
              <textarea msd-elastic ng-model="dep.exclusions"
                        ng-list
                        placeholder="(Optional) comma separated groupId:artifactId list">
              </textarea>
            </td>
            <td>
              <button class="btn btn-default btn-sm fa fa-remove"
                   ng-click="removeInterpreterDependency(dep.groupArtifactVersion)">
              </button>
            </td>
          </tr>

          <tr>
            <td>
              <input ng-model="newInterpreterSetting.depArtifact"
                     placeholder="groupId:artifactId:version or local file path"
                     style="width: 100%" />
            </td>
            <td>
              <textarea msd-elastic ng-model="newInterpreterSetting.depExclude"
                        ng-list
                        placeholder="(Optional) comma separated groupId:artifactId list">
              </textarea>
            </td>
            <td>
              <button class="btn btn-default btn-sm fa fa-plus" ng-click="addNewInterpreterDependency()">
              </button>
            </td>
          </tr>
        </table>

        <span class="btn btn-primary" ng-click="addNewInterpreterSetting()">
          Save
        </span>
        <span class="btn btn-default" ng-click="cancelInterpreterSetting()">
          Cancel
        </span>
      </div>
    </div>
  </div>
</div>
